#include "es_task.h"

#define   Faults_Task_Pro                    15             /* <Correspond message processing tasks>  Priority */
#define   Faults_Task_StackSize              (800ul)        /* <Correspond message processing tasks>  Stack size */
TaskHandle_t  Faults_Handler;                               /* <Correspond message processing tasks>  handle */
void Faults_Task(void *pvParameters);                       /* <Correspond message processing tasks>  Function */

#define   Correspond_Task_Pro                5              /* <Correspond message processing tasks>  Priority */
#define   Correspond_Task_StackSize          (800ul)        /* <Correspond message processing tasks>  Stack size */
TaskHandle_t  Correspond_Handler;                           /* <Correspond message processing tasks>  handle */
void Correspond_Task(void *pvParameters);                   /* <Correspond message processing tasks>  Function */

/**
 * @brief : FreeRTOS task creation and start scheduling
 * @param : None
 * @return: None
 * @author: Barry
 * @modify: None
 */
void AppCreateTask(void)
{
    /* Entering the critical zone */
    taskENTER_CRITICAL(); 

    /* Create fault detect processing tasks */		
    xTaskCreate((TaskFunction_t )Faults_Task,             		    /* Task Functions */
                (const char*    )"Faults_Task",           		    /* Task Name */
                (uint16_t       )Faults_Task_StackSize,  		    /* Task stack size */
                (void*          )NULL,                        		/* Parameters passed to the task function */
                (UBaseType_t    )Faults_Task_Pro,         		    /* Task Priority */
                (TaskHandle_t*  )&Faults_Handler);       		    /* Task handle */

    /* Create correspond message processing tasks */		
    xTaskCreate((TaskFunction_t )Correspond_Task,             		/* Task Functions */
                (const char*    )"Correspond_Task",           		/* Task Name */
                (uint16_t       )Correspond_Task_StackSize,  		/* Task stack size */
                (void*          )NULL,                        		/* Parameters passed to the task function */
                (UBaseType_t    )Correspond_Task_Pro,         		/* Task Priority */
                (TaskHandle_t*  )&Correspond_Handler);       		/* Task handle */

    log_i("Task creat successful.\r\n");
    /* Exit critical zone */
    taskEXIT_CRITICAL();  

    /* Turn on task scheduling */
    vTaskStartScheduler();	                                                                                                                                                         
}

void Faults_Task(void *pvParameters)
{
    for(;;)
    {
        log_e("FreeRTOS running...\r\n");
        vTaskDelay(200);  
    }
}


void Correspond_Task(void *pvParameters)
{
    drv_dbg_config();
    drv_host_config();

    for(;;)
    {   
        log_w("FreeRTOS running...\r\n");
        vTaskDelay(200);  
    }
}
